package cn.jolyoulu.common.core.queue.delayed;

import cn.jolyoulu.common.core.queue.delayed.observer.DelayedTaskSubject;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: JolyouLu
 * @Date: 2023/4/15 20:34
 * @Description
 */
@Getter
public class DelayedTaskBootStrap {

    /**
     * 消费者的数量
     */
    private final Integer size;

    /**
     * 消费者数组
     */
    private final List<Thread> threadList;

    /**
     * 生产者
     */
    private final DelayedTaskProducer delayedTaskProducer;

    /**
     * 观察者主持信息
     */
    private final DelayedTaskSubject delayedTaskSubject;

    public DelayedTaskBootStrap(Integer size, DelayedTaskProducer delayedTaskProducer, DelayedTaskSubject delayedTaskSubject) {
        this.size = size;
        this.threadList = new ArrayList<>();
        //初始化消费者的数量
        for (int i = 0; i < this.size; i++) {
            Thread thread = new Thread(new DelayedTaskConsumer(delayedTaskSubject,delayedTaskProducer.getDelayedTaskQueue()));
            thread.setName("delayed-task-consumer-" + i);
            thread.start();
            threadList.add(thread);
        }
        this.delayedTaskProducer = delayedTaskProducer;
        this.delayedTaskSubject = delayedTaskSubject;
    }

}
